﻿<UserControl x:Class="FullDayStrategyPlugin.StrategyControl"
			 x:ClassModifier="internal"
			 
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             
             xmlns:Converters="clr-namespace:Utils.Wpf.Converters;assembly=Utils" Background="#1F1F1F"
             
             mc:Ignorable="d"
             
             d:DesignHeight="130" 
             d:DataContext="{d:DesignInstance Type=FD2:StrategyControlVM}" >

	<UserControl.Resources>
		<ResourceDictionary>
			<Converters:MultiplierConverter x:Key="MultiplierConverter" />
			<Converters:EnumToBooleanConverter x:Key="EnumToBooleanConverter" />
			<Converters:NegatedEnumToBooleanConverter x:Key="NegatedEnumToBooleanConverter" />
			<ResourceDictionary.MergedDictionaries>
				<ResourceDictionary Source="pack://application:,,,/Plugins;component/PluginTheme.xaml" />
			</ResourceDictionary.MergedDictionaries>
		</ResourceDictionary>
	</UserControl.Resources>
	<Grid>
		<Grid.ColumnDefinitions>
			<ColumnDefinition Width="Auto" />
			<ColumnDefinition Width="Auto" />
			<ColumnDefinition Width="Auto" />
			<ColumnDefinition Width="Auto" />
			<ColumnDefinition Width="Auto" />
			<ColumnDefinition Width="Auto" />
			<ColumnDefinition Width="Auto" />
			<ColumnDefinition Width="Auto" />
			<ColumnDefinition Width="Auto" />
			<ColumnDefinition Width="Auto" />
			<ColumnDefinition Width="Auto" />
			<ColumnDefinition Width="Auto" />
			<ColumnDefinition Width="Auto" />
			<ColumnDefinition Width="Auto" />
			<ColumnDefinition Width="Auto" />
			<ColumnDefinition Width="Auto" />
			<ColumnDefinition Width="Auto" />
		</Grid.ColumnDefinitions>
		<Grid.RowDefinitions>
			<RowDefinition Height="*" />
			<RowDefinition Height="*" />
			<RowDefinition Height="*" />
			<RowDefinition Height="*" />
			<RowDefinition Height="*" />
		</Grid.RowDefinitions>

		<TextBlock Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="12" Text="Execution Parameters" HorizontalAlignment="Center" VerticalAlignment="Center" x:Name="Header" Margin="6" />

		<!-- Mode -->
		<GroupBox Grid.Row="1" Grid.Column="0" Grid.RowSpan="3" Margin="5,0,5,0" Header="Mode" >
			<StackPanel>
				<RadioButton GroupName="Mode" Content="Up" IsChecked="{Binding ExecutionDirection, Converter={StaticResource EnumToBooleanConverter}, ConverterParameter=Up, Mode=TwoWay, ValidatesOnDataErrors=True, NotifyOnValidationError=True, ValidatesOnExceptions=True, UpdateSourceTrigger=PropertyChanged}" />
				<RadioButton GroupName="Mode" Content="Down" IsChecked="{Binding ExecutionDirection, Converter={StaticResource EnumToBooleanConverter}, ConverterParameter=Down, Mode=TwoWay, ValidatesOnDataErrors=True, NotifyOnValidationError=True, ValidatesOnExceptions=True, UpdateSourceTrigger=PropertyChanged}" />
				<RadioButton GroupName="Mode" Content="Up &amp; Down" IsChecked="{Binding ExecutionDirection, Converter={StaticResource EnumToBooleanConverter}, ConverterParameter=UpAndDown, Mode=TwoWay, ValidatesOnDataErrors=True, NotifyOnValidationError=True, ValidatesOnExceptions=True, UpdateSourceTrigger=PropertyChanged}" />
			</StackPanel>
			<GroupBox.ToolTip>
				<StackPanel>
					<TextBlock Foreground="Black" FontWeight="Bold" Text="Mode" />
					<TextBlock Foreground="Black" Text="Selects if operations will be done on markets going up, down or both." />
				</StackPanel>
			</GroupBox.ToolTip>
		</GroupBox>

		<!-- Internal Separator -->
		<Border Grid.Row="1" Grid.Column="1" Grid.RowSpan="4" BorderBrush="{StaticResource SelectedRowBrush}" Background="{StaticResource SelectedRowBrush}" BorderThickness="1" Margin="10,0,10,0" />

		<!-- Numeric Parameters -->
		<TextBlock Grid.Row="1" Grid.Column="2" Margin="3,3,6,3" Text="Stop Loss" />
		<TextBox Grid.Row="1" Grid.Column="3" Margin="0,1,0,1" HorizontalContentAlignment="Right" Text="{Binding StopLoss, ValidatesOnDataErrors=True, ValidatesOnExceptions=True, NotifyOnValidationError=True, UpdateSourceTrigger=PropertyChanged}" Width="{Binding ActualWidth, ElementName=Header, Converter={StaticResource MultiplierConverter}, ConverterParameter=0.3}" >
			<TextBox.ToolTip>
				<StackPanel>
					<TextBlock Foreground="Black" FontWeight="Bold" Text="Stop Loss" />
					<TextBlock Foreground="Black" Text="When inside an operation our loss becomes equal to this value the operation will be closed at current market price." />
				</StackPanel>
			</TextBox.ToolTip>
		</TextBox>
		<TextBlock Grid.Row="1" Grid.Column="4" Margin="3,3,6,3" Text="%" />

		<TextBlock Grid.Row="2" Grid.Column="2" Margin="3,3,6,3" Text="Max Inverse Value" IsEnabled="{Binding ExecutionDirection, Converter={StaticResource EnumToBooleanConverter}, ConverterParameter=UpAndDown}" />
		<TextBox Grid.Row="2" Grid.Column="3" Margin="0,1,0,1" HorizontalContentAlignment="Right" Text="{Binding MaxInverseValue, ValidatesOnDataErrors=True, ValidatesOnExceptions=True, NotifyOnValidationError=True, UpdateSourceTrigger=PropertyChanged}" Width="{Binding ActualWidth, ElementName=Header, Converter={StaticResource MultiplierConverter}, ConverterParameter=0.3}" IsEnabled="{Binding ExecutionDirection, Converter={StaticResource EnumToBooleanConverter}, ConverterParameter=UpAndDown}" >
			<TextBox.ToolTip>
				<StackPanel>
					<TextBlock Foreground="Black" FontWeight="Bold" Text="Max Inverse Value" />
					<TextBlock Foreground="Black" Text="The engine only will open a short or long possition if the opposite maximum value is less than this one. -1 to disable it." />
				</StackPanel>
			</TextBox.ToolTip>
		</TextBox>
		<TextBlock Grid.Row="2" Grid.Column="4" Margin="3,3,6,3" Text="%" IsEnabled="{Binding ExecutionDirection, Converter={StaticResource EnumToBooleanConverter}, ConverterParameter=UpAndDown}" />

		<TextBlock Grid.Row="3" Grid.Column="2" Margin="3,3,6,3" Text="Max Profit" />
		<TextBox Grid.Row="3" Grid.Column="3" Margin="0,1,0,1" HorizontalContentAlignment="Right" Text="{Binding MaxProfit, ValidatesOnDataErrors=True, ValidatesOnExceptions=True, NotifyOnValidationError=True, UpdateSourceTrigger=PropertyChanged}" Width="{Binding ActualWidth, ElementName=Header, Converter={StaticResource MultiplierConverter}, ConverterParameter=0.3}" >
			<TextBox.ToolTip>
				<StackPanel>
					<TextBlock Foreground="Black" FontWeight="Bold" Text="Max Profit" />
					<TextBlock Foreground="Black" Text="The engine will close an operation when the max profit value is reached if different from 0." />
				</StackPanel>
			</TextBox.ToolTip>
		</TextBox>
		<TextBlock Grid.Row="3" Grid.Column="4" Margin="3,3,6,3" Text="%" />

		<!-- Internal Separator -->
		<Border Grid.Row="1" Grid.Column="5" Grid.RowSpan="4" BorderBrush="{StaticResource SelectedRowBrush}" Background="{StaticResource SelectedRowBrush}" BorderThickness="1" Margin="10,0,10,0" />

		<!-- Numeric Parameters -->
		<TextBlock Grid.Row="1" Grid.Column="6" Margin="3,3,6,3" Text="Volume increment" IsEnabled="{Binding VolumeMode, Converter={StaticResource NegatedEnumToBooleanConverter}, ConverterParameter=Disabled}" />
		<TextBox Grid.Row="1" Grid.Column="7" Margin="0,1,0,1" HorizontalContentAlignment="Right" Text="{Binding VolumeIncrement, ValidatesOnDataErrors=True, ValidatesOnExceptions=True, NotifyOnValidationError=True, UpdateSourceTrigger=PropertyChanged}" Width="{Binding ActualWidth, ElementName=Header, Converter={StaticResource MultiplierConverter}, ConverterParameter=0.3}" IsEnabled="{Binding VolumeMode, Converter={StaticResource NegatedEnumToBooleanConverter}, ConverterParameter=Disabled}" >
			<TextBox.ToolTip>
				<StackPanel>
					<TextBlock Foreground="Black" FontWeight="Bold" Text="Stop Loss" />
					<TextBlock Foreground="Black" Text="When inside an operation our loss becomes equal to this value the operation will be closed at current market price." />
				</StackPanel>
			</TextBox.ToolTip>
		</TextBox>

		<TextBlock Grid.Row="2" Grid.Column="6" Margin="3,3,6,3" Text="Initial Volume" />
		<TextBox Grid.Row="2" Grid.Column="7" Margin="0,0,0,1"  HorizontalContentAlignment="Right" Text="{Binding QuantityToBuy, ValidatesOnDataErrors=True, ValidatesOnExceptions=True, NotifyOnValidationError=True, UpdateSourceTrigger=PropertyChanged}" Width="{Binding ActualWidth, ElementName=Header, Converter={StaticResource MultiplierConverter}, ConverterParameter=0.3}" >
			<TextBox.ToolTip>
				<StackPanel>
					<TextBlock Foreground="Black" FontWeight="Bold" Text="Initial Volume" />
					<TextBlock Foreground="Black" Text="The number of items to buy/sell on each operation." />
				</StackPanel>
			</TextBox.ToolTip>
		</TextBox>

		<TextBlock Grid.Row="3" Grid.Column="6" Margin="3,3,6,3" Text="Max Volume" />
		<TextBox Grid.Row="3" Grid.Column="7" Margin="0,1,0,1" HorizontalContentAlignment="Right" Text="{Binding MaxVolume, ValidatesOnDataErrors=True, ValidatesOnExceptions=True, NotifyOnValidationError=True, UpdateSourceTrigger=PropertyChanged}" Width="{Binding ActualWidth, ElementName=Header, Converter={StaticResource MultiplierConverter}, ConverterParameter=0.3}" IsEnabled="{Binding VolumeMode, Converter={StaticResource NegatedEnumToBooleanConverter}, ConverterParameter=Disabled}" >
			<TextBox.ToolTip>
				<StackPanel>
					<TextBlock Foreground="Black" FontWeight="Bold" Text="Max Volume" />
					<TextBlock Foreground="Black" Text="The maximum volume that the engine will operate, even if the volume mode requests a higher volume." />
				</StackPanel>
			</TextBox.ToolTip>
		</TextBox>

		<TextBlock Grid.Row="4" Grid.Column="6" Margin="3,3,6,3" Text="Reset Threshold" IsEnabled="{Binding VolumeMode, Converter={StaticResource NegatedEnumToBooleanConverter}, ConverterParameter=Disabled}" />
		<TextBox Grid.Row="4" Grid.Column="7" Margin="0,1,0,1" HorizontalContentAlignment="Right" Text="{Binding ResetThreshold, ValidatesOnDataErrors=True, ValidatesOnExceptions=True, NotifyOnValidationError=True, UpdateSourceTrigger=PropertyChanged}" Width="{Binding ActualWidth, ElementName=Header, Converter={StaticResource MultiplierConverter}, ConverterParameter=0.3}" IsEnabled="{Binding VolumeMode, Converter={StaticResource NegatedEnumToBooleanConverter}, ConverterParameter=Disabled}" >
			<TextBox.ToolTip>
				<StackPanel>
					<TextBlock Foreground="Black" FontWeight="Bold" Text="Stop Loss" />
					<TextBlock Foreground="Black" Text="When inside an operation our loss becomes equal to this value the operation will be closed at current market price." />
				</StackPanel>
			</TextBox.ToolTip>
		</TextBox>
		<TextBlock Grid.Row="4" Grid.Column="8" Margin="3,3,6,3" Text="%" IsEnabled="{Binding VolumeMode, Converter={StaticResource NegatedEnumToBooleanConverter}, ConverterParameter=Disabled}" />

		<!-- Internal Separator -->
		<Border Grid.Row="1" Grid.Column="9" Grid.RowSpan="4" BorderBrush="{StaticResource SelectedRowBrush}" Background="{StaticResource SelectedRowBrush}" BorderThickness="1" Margin="10,0,10,0" />

		<!-- Numeric Parameters 2 -->
		
		<!-- Internal Separator -->
		<Border Grid.Row="1" Grid.Column="13" Grid.RowSpan="4" BorderBrush="{StaticResource SelectedRowBrush}" Background="{StaticResource SelectedRowBrush}" BorderThickness="1" Margin="10,0,10,0" />
		
		<!-- Volume management -->
		<GroupBox Grid.Row="1" Grid.Column="14" Grid.RowSpan="3" Margin="5,0,5,0" Header="Volume mode" >
			<StackPanel>
				<RadioButton GroupName="VolumeMode" Content="Disabled" IsChecked="{Binding VolumeMode, Converter={StaticResource EnumToBooleanConverter}, ConverterParameter=Disabled, Mode=TwoWay, ValidatesOnDataErrors=True, ValidatesOnExceptions=True, NotifyOnValidationError=True, UpdateSourceTrigger=PropertyChanged}" />
				<RadioButton GroupName="VolumeMode" Content="Arithmetic" IsChecked="{Binding VolumeMode, Converter={StaticResource EnumToBooleanConverter}, ConverterParameter=Arithmetic, Mode=TwoWay, ValidatesOnDataErrors=True, NotifyOnValidationError=True, ValidatesOnExceptions=True, UpdateSourceTrigger=PropertyChanged}" />
				<RadioButton GroupName="VolumeMode" Content="Geometric" IsChecked="{Binding VolumeMode, Converter={StaticResource EnumToBooleanConverter}, ConverterParameter=Geometric, Mode=TwoWay, ValidatesOnDataErrors=True, NotifyOnValidationError=True, ValidatesOnExceptions=True, UpdateSourceTrigger=PropertyChanged}" />
			</StackPanel>
			<GroupBox.ToolTip>
				<StackPanel>
					<TextBlock Foreground="Black" FontWeight="Bold" Text="Volume mode" />
					<TextBlock Foreground="Black" Text="Selects if volume will be constant or if will increase in an Geometric or Arithmetic progression ." />
				</StackPanel>
			</GroupBox.ToolTip>
		</GroupBox>

		<!-- Internal Separator -->
		<Border Grid.Row="1" Grid.Column="15" Grid.RowSpan="4" BorderBrush="{StaticResource SelectedRowBrush}" Background="{StaticResource SelectedRowBrush}" BorderThickness="1" Margin="10,0,10,0" />

		<!-- Boolean Parameters -->
		<CheckBox Grid.Row="1" Grid.Column="16" Content="Invert Logic" IsChecked="{Binding InvertLogic, Mode=TwoWay}" >
			<CheckBox.ToolTip>
				<StackPanel>
					<TextBlock Foreground="Black" FontWeight="Bold" Text="Invert Logic" />
					<TextBlock Foreground="Black" Text="If active a sell is done when a buy should be done and the other way around." />
				</StackPanel>
			</CheckBox.ToolTip>
		</CheckBox>
		<CheckBox Grid.Row="2" Grid.Column="16" Content="StopLoss at 0" IsChecked="{Binding StopLossAt0, Mode=TwoWay}" IsEnabled="{Binding ExecutionDirection, Converter={StaticResource EnumToBooleanConverter}, ConverterParameter=UpAndDown}">
			<CheckBox.ToolTip>
				<StackPanel>
					<TextBlock Foreground="Black" FontWeight="Bold" Text="Stop Loss at 0" />
					<TextBlock Foreground="Black" Text="If the mode is UpDown the stoploss will be executed when returning at 0 instead of the opposite StopLoss." />
				</StackPanel>
			</CheckBox.ToolTip>
		</CheckBox>
		<CheckBox Grid.Row="3" Grid.Column="16" Content="Multi Operation" IsChecked="{Binding MultipleOperations, Mode=TwoWay}" >
			<CheckBox.ToolTip>
				<StackPanel>
					<TextBlock Foreground="Black" FontWeight="Bold" Text="Multi Operation" />
					<TextBlock Foreground="Black">
                                Enable to execute more than one operation each day.<LineBreak/>
                                On Up or Down strategies a new operation will be launch when reaching the opening price.<LineBreak/>
                                On Up And Down when closing the possition a new one of the opposite sign will be done.
					</TextBlock>
				</StackPanel>
			</CheckBox.ToolTip>
		</CheckBox>

		<CheckBox Grid.Row="4" Grid.Column="16" Content="Dynamic Stop" IsChecked="{Binding DynamicStop, Mode=TwoWay}" >
			<CheckBox.ToolTip>
				<StackPanel>
					<TextBlock Foreground="Black" FontWeight="Bold" Text="Dynamic Stop" />
					<TextBlock Foreground="Black" Text="The stop value will be calculated as the stop loss percentage of the highest/lowest value received from the operation start." />
				</StackPanel>
			</CheckBox.ToolTip>
		</CheckBox>

	</Grid>
</UserControl>
